<template>
  <div class="mailPage">
    <div class="header">
      <div class="title">
        <span class="icon sz_envelopeOpenF"></span>
        <span class="txt">邮件</span>
      </div>
      <!-- <div class="navList">
        <span
          :class="currentNav == index ? 'active' : ''"
          @click="changeNav(index)"
          v-for="(item, index) in navList"
          :key="item.name + index"
          >{{ item.name }}</span
        >
      </div> -->
      <span class="more" @click="moreMail"
        >更多 <i class="sz_arrows_right"></i
      ></span>
    </div>
    <div class="content">
      <div class="mailList">
        <div
          class="mailItem"
          @click="toMailDetail(item)"
          v-for="(item, index) in mailList.slice(0, 5)"
          :key="index"
        >
          <span class="mainIcon"></span>
          <span class="title" :title="item.title ">{{ item.title }}</span>
          <span style="display:none" class="sender">{{ item.sender }}</span>
          <span class="time">{{ item.sendDate.split(" ")[0] }}</span>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      mailList: [
        // {
        //   title: "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
        //   link: "",
        //   sendDate: "2022-12-12 11:11:11",
        //   sender: "张三",
        // },
        // {
        //   des: "11111111111111111",
        //   link: "",
        //   date: "2022-12-12",
        //   sender: "张三",
        // },
        // {
        //   des: "11111111111111111",
        //   link: "",
        //   date: "2022-12-12",
        //   sender: "张三",
        // },
        // {
        //   des: "11111111111111111",
        //   link: "",
        //   date: "2022-12-12",
        //   sender: "张三",
        // },
        // {
        //   des: "11111111111111111",
        //   link: "",
        //   date: "2022-12-12",
        //   sender: "张三",
        // },
      ],
      currentNav: 0, //当前页签
      moreLink: "", //更多链接
    };
  },
  created() {},

  mounted() {
    this.getMailData();
  },
  methods: {
    // 获取邮件数据
    getMailData() {
      this.axios({
        url: "/seeyon/rest/select/email",
        method: "post",
        headers: {
          "Content-Type": "application/json",
          "token":localStorage.getItem("restToken"),
        },
        data: {
          loginName: localStorage.getItem("loginName")
        },
      }).then((res) => {
        console.log("获取邮件数据", res);
        this.mailList = res.data.data.emailList;
        this.moreLink = res.data.data.moreUrl;
      });
    },
    // 切换页签
    changeNav(index) {
      this.currentNav = index;
    },
    // 更多新闻
    moreMail() {
      // window.open('/seeyon' + this.moreLink, "_blank");
      this.axios({
        url: `/seeyon/oasso.do?method=redirect&loginName=${localStorage.getItem("loginName")}&url=${encodeURIComponent("/seeyon" + this.moreLink)}`,
        method: "get",
        headers: {
          "Content-Type": "application/json",
        },
      }).then((res) => {
        console.log("点击新闻数据", res);
        window.open(res.data, "_blank");
      });
    },
    // 点击新闻
    toMailDetail(item) {
      // window.open('/seeyon' + this.moreLink, "_blank");
      this.axios({
        url: `/seeyon/oasso.do?method=redirect&loginName=${localStorage.getItem("loginName")}&url=${encodeURIComponent("/seeyon" + this.moreLink)}`,
        method: "get",
        headers: {
          "Content-Type": "application/json",
        },
      }).then((res) => {
        console.log("点击新闻数据", res);
        window.open(res.data, "_blank");
      });
    },
  },
};
</script>
<style lang="less" scoped>
.mailPage {
  width: 100%;
  height: 100%;
  .header {
    height: 50px;
    display: flex;
    align-items: center;
    position: relative;
    .title {
      font-weight: 600;
      font-size: 20px;
      line-height: 50px;
      .icon {
        margin-right: 5px;
        line-height: 50px;
        color: #1371ff;
        font-size: 20px;
        margin-right: 10px;
      }
    }
    .navList {
      margin-left: 20px;
      display: flex;
      height: 30px;
      span {
        padding: 0 20px;
        background-color: aliceblue;
        margin: 0 5px;
        border-radius: 15px;
        line-height: 30px;
        cursor: pointer;
      }
      .active {
        background-color: #2c85fb;
        color: #fff;
      }
    }
    .more {
      position: absolute;
      right: 0px;
      cursor: pointer;
      color: #a6a9ad;
      font-size: 14px;
      i {
        font-size: 12px;
      }
    }
  }
  .content {
    height: calc(100% - 50px);
    position: relative;
    .imgList {
      height: 100%;
      width: 300px;
      overflow: hidden;
      margin-right: 10px;
      .imgItem {
        height: 100%;
        float: left;
        img {
          width: 100%;
        }
      }
    }
    .mailList {
      .mailItem {
        display: flex;
        align-items: center;
        width: 100%;
        line-height: 36px;
        height: 36px;
        .mainIcon{
          width: 22px;
          height: 20px;
          background-image: url(@/imgs/mail.png);
          background-repeat: no-repeat;
          background-size: 100%;
          color: #d7d93d;
          margin-right: 3px;
        }
        .title {
          color: #121213;
          width: calc(100% - 140px);
          display: inline-block;
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
          cursor: pointer;
        }
        .sender {
          color: #c7ccd1;
          width: 120px;
          display: inline-block;
          text-align: right;
          cursor: pointer;
          vertical-align: top;
        }
        .time {
          color: #c7ccd1;
          width: 120px;
          display: inline-block;
          text-align: right;
          cursor: pointer;
          vertical-align: top;
        }
      }
    }
  }
}
</style>